package cn.detu.ln.controller;

import cn.detu.ln.entity.Student;
import cn.detu.ln.service.StudentService;
import cn.detu.ln.utils.PageUtil;
import cn.detu.ln.utils.RestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    // GET请求获取用户列表数据
    // localhost:1314/user/selectAll
    @GetMapping("{url}")
    public RestUtil userGet(@PathVariable String url, Student student, PageUtil pageUtil, String search){
        switch (url){
            case "selectAll": return studentService.selectAll();
            case "selectOne": return studentService.select(student.getStuNum());
            case "studentDelete":return studentService.studentDelete(student.getStuNum());
            case "queryStudentByPage":return studentService.queryStudentByPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
            // 按学号查询
            case "queryStudentByStuNumPage":return studentService.queryStudentByStuNumPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
            // 按班级查询
            case "queryStudentByStuClassPage":return studentService.queryStudentByStuClassPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
        }

        return null;
    }
    @PostMapping("{url}")
    public RestUtil userPost(@PathVariable String url, Student student,String newPwd){
        switch (url){
            case "studentUpdate":return studentService.studentUpdate(student);
            case "studentInsert":return studentService.studentInsert(student);
            // 实现登录
            case "login":
                return studentService.login(student);
            case "updatePwd":return studentService.studentUpdatePwd(student,newPwd);
        }
        return null;
    }
    @GetMapping("queryStudentByNum/{stuNum}")
    public Student queryStudentByNum(@PathVariable("stuNum") Long stuNum){
        return studentService.queryStudentByNum(stuNum);
    }
}
